import time

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

driver = webdriver.Chrome(service=Service('chromedriver.exe'))
driver.maximize_window()

# # 8.元素定位-XPATH定位
# driver.get('http://www.baidu.com')
# driver.find_element(By.XPATH, '//*[@id="kw"]').send_keys('python')
# driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div[5]/div[2]/div/form/span[2]/input').click()

# 7.元素定位-CSS_SELECTOR定位
driver.get('https://www.baidu.com')
driver.find_element(By.CSS_SELECTOR, '#kw').send_keys('python')
driver.find_element(By.CSS_SELECTOR, '[autocomplete="off"]').send_keys('python')
driver.find_element(By.CSS_SELECTOR, '#s-top-left > a:nth-child(4)').click()

# 6.元素定位-PARTIAL_LINK_TEXT定位
# driver.get('https://www.baidu.com')
# driver.find_element(By.PARTIAL_LINK_TEXT, '图').click()

# 5.元素定位-LINK_TEXT定位
# driver.get('https://www.baidu.com')
# driver.find_element(By.LINK_TEXT, '图片').click()

# 4.元素定位-TAG_NAME定位
# driver.get('http://www.baidu.com')
# driver.find_elements(By.TAG_NAME, 'input')[7].send_keys('python')

# 3.元素定位CLASS_NAME定位
# driver.get('https://www.baidu.com')
# driver.find_element(By.CLASS_NAME, 's_ipt').send_keys('python')
# driver.get('https://www.bilibili.com/')
# driver.find_elements(By.CLASS_NAME, 'channel-icons__item')[1].click()

# 2.NAME定位
# driver.find_element(By.NAME, 'wd').send_keys('python')

# 1.ID定位
# driver.find_element(By.ID, 'kw').send_keys('python')

time.sleep(2)